let app = {
  init: function () {
    this.id = 'app_iframe'
    var para = document.createElement('iframe')
    para.setAttribute('id', this.id)
    para.setAttribute('style', 'display:none')
    document.body.appendChild(para)
  },
  checkLogin: function () {
    this.jump('checkLogin')
  },
  login: function () {
    this.jump('login', {'reload': 1,'type': 0})
  },
  goods: function (params) {
    this.jump('goods', params)
  },
  special: function (params) {
    this.jump('special', params)
  },
  share: function (params) {
    this.jump('share', params)
  },
  close: function() {
    this.jump('close');
  },
  // web页面打开
  openWeb: function (param) {
    this.jump('web', param)
  },
  //返回首页
  backHome: function () {
    this.jump('backHome')
  },
  jump: function (type, params) {
    params = arguments[1] || {}
    let url = 'sdjj' + '://' + type
    var i = 0
    for (var key in params) {
      if (i === 0) { url += '?' } else { url += '&' }
      if (typeof (params[key]) === 'object') {
        url += key + '=' + JSON.stringify(params[key])
      } else {
        url += key + '=' + encodeURIComponent(params[key])
      }
      i++
    }
    if (i === 0) {url += '?t=' + new Date().getTime()} 
    else {url += '&t=' + new Date().getTime()}
    let para = document.getElementById('app_iframe')
    // console.log(url)
    para.setAttribute('src', url)
  }
}
app.init()
export default app
